Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@leafygreen-ui/hooks
Advanced tools
yarn add @leafygreen-ui/hooks
npm install @leafygreen-ui/hooks
Hook to create and remove eventListeners
import { useEventListener } from '@leafygreen-ui/hooks';
useEventListener('click', handleClick, { enabled });
Prop | Type | Description | Default |
---|---|---|---|
type | Global Event Handler , string | Type of event to listen for. | |
eventCallback | function | Callback executed when event is triggered. | |
optional | object | Optional third argument passed to function with implementation specifications. | |
optional.options | AddEventListenerOptions excluding once | Parameter to specify options passed to the eventListener. To enable the once option, see optional.enabled . | |
optional.enabled | boolean , 'once' | Determines whether the event handler is attached or not. Setting this to "once" will ensure the event handler will be detached after the initial time an event is triggered. | true |
optional.dependencies | Array | Array to be passed to useEffect hook, such that the hook will only run if the array's values have changed. | [enabled, type] |
optional.element | Document , HTMLElement | The DOM node to attach the event handler to. Defaults to document . | document |
Hook that listens for EscapeKey
press.
import { useEscapeKey } from '@leafygreen-ui/hooks';
useEscapeKey(handleEscapeCallback);
Prop | Type | Description | Default |
---|---|---|---|
callback | function | Callback executed when EscapeKey is pressed. | |
optional | object | Optional argument passed to function with implementation specifications. See supported parameters for useEventHandler. |
import { useMutationObserver } from '@leafygreen-ui/hooks';
const lastTimeContentElMutated = useMutationObserver(
target,
mutationOptions,
() => Date.now(),
adjustOnMutation,
);
Prop | Type | Description | Default |
---|---|---|---|
target | HTMLElement , null | HTMLElement to subscribe to changes to. | |
options | MutationObserverInit | Object with information about what DOM changes to subscribe to. Docs here | |
callback | function | Callback function to execute inside of MutationObserver instance. | |
enabled | boolean | Determines whether the event handler is attached or not. | true |
Hook to subscribe to changes in viewport size
const viewportSize = useViewportSize();
Hook to create a Poller that polls at a given interval.
If your onPoll
handler returns a Promise
it will wait for the Promise to resolve or reject before scheduling the next interval.
This hooks also makes use of the Page Visibility API. If the page is hidden
then polling will stop. When a page becomes visible
again then polling will resume.
import { usePoller } from '@leafygreen-ui/hooks';
usePoller(onPoll, {
interval: 30000,
immediate: true,
enabled: true,
});
Prop | Type | Description | Default |
---|---|---|---|
onPoll | function | Callback executed when poll interval occurs. | |
optional.interval | number | What interval the onPoll should be called. | 30000 |
optional.immediate | boolean | If we immediately poll, if false we wait till first interval occurs. | true |
optional.enabled | boolean | Is polling enabled. | true |
Hook to retrieve a value from the previous render.
import { usePrevious } from '@leafygreen-ui/hooks';
const Example = ({nextValue: number}) => {
const value = usePrevious(nextValue);
return <div>{value}</div>;
}
// First render
<Example nextValue={42} /> // will render an empty `div`
// Second render
<Example nextValue={2020} /> // will render "42"
// Third render
<Example nextValue={0} /> // will render "2020"
Drop-in replacement for useLayoutEffect
that does not produce warnings during server-side rendering. If your project uses the react-hooks/exhaustive-deps
ESLint rule, it's recommended to add useIsomorphicLayoutEffect
to the additionalHooks
of the rule. Example:
rules: {
'react-hooks/exhaustive-deps': [
'warn',
{
additionalHooks: '(useIsomorphicLayoutEffect)'
}
]
}
Generates an SSR-compatible unique id based on a prefix string and an optional idProp parameter.
import { useIdAllocator } from '@leafygreen-ui/hooks';
useIdAllocator({ prefix: 'select-component', id: idProp });
Returns a MutableRefObject from the forwarded ref.
import { useForwardedRef } from '@leafygreen-ui/hooks';
const MyComponent = React.forwardRef((props, forwardedRef) => {
const ref = useForwawrdedRef(forwardedRef, null);
});
Prop | Type | Description | Default |
---|---|---|---|
forwardedRefOrRefs | SettableRef , Array<SettableRef> , null | The forwarded ref | |
initialValue | T | Initial value of the ref |
useDynamicRefs is a hook that allows you to create multiple refs for dynamically created elements. Use the prefix
property to create multiple sets of dynamic refs.
import { useDynamicRefs } from '@leafygreen-ui/hooks';
const getRef = useDynamicRefs();
...
return ['a','b','c'].map(x => {
const divRef = getRef(x)
return <div ref={divRef}>{x}</div>
})
Prop | Type | Description | Default |
---|---|---|---|
prefix | string | Optional prefix to that genterates a ref name space |
FAQs
LeafyGreen UI Kit Custom Hooks
The npm package @leafygreen-ui/hooks receives a total of 71,052 weekly downloads. As such, @leafygreen-ui/hooks popularity was classified as popular.
We found that @leafygreen-ui/hooks demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.